package smarties.style;

import java.awt.Color;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name = "color")
public class SmartColor
{
	@XmlElement(name = "r")
	private final int	r;

	@XmlElement(name = "g")
	private final int	g;

	@XmlElement(name = "b")
	private final int	b;

	@XmlElement(name = "a")
	private final float	a;

	private Color		color		= null;
	private Color		rgbColor	= null;

	public Color getColor()
	{
		if (this.color == null)
		{
			this.color = new Color(this.r / 255f, this.g / 255f, this.b / 255f,
					this.a);
		}

		return this.color;
	}

	public Color getRGBColor()
	{
		if (this.rgbColor == null)
		{
			this.rgbColor = new Color(this.r, this.g, this.b);
		}

		return this.rgbColor;
	}

	public SmartColor(int r, int g, int b, float a)
	{
		this.r = r;
		this.g = g;
		this.b = b;
		this.a = a;
	}

	/**
	 * Pour JaxB
	 */
	@SuppressWarnings("unused")
	private SmartColor()
	{
		this.r = 1;
		this.g = 1;
		this.b = 1;
		this.a = 1;
	}
}
